/// ----------------------------------------------
/// !!! 此文件由工具自动生成，请勿直接修改。 !!!
/// !!! Tabs to Spaces !!!
/// !!! 生成时间：2021-05-10 14:57:44.363
/// ----------------------------------------------

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
using DLC.Module.DataTable;

namespace DLC.Game.DataTable.ArchiveBytes.Editor
{
    public class ExcelExampleTempExample_1BytesAssetPostprocessor : AssetPostprocessor 
    {
        private const string filePath = "Assets/Example/Excel/Example 1.xlsx";
        private const string assetFilePath = "Assets/Example/Excel/ExcelExampleTemp_Example_1.byte.txt";
        private const string sheetName = "ExcelExampleTemp";
    
        static void OnPostprocessAllAssets (string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            foreach (string asset in importedAssets) 
            {
                if (!filePath.Equals (asset))
                    continue;

                ExcelExampleTemp dataTable = new ExcelExampleTemp();
                var data = AssetDatabase.LoadAssetAtPath<TextAsset>(assetFilePath);
                if (data != null) {
                    dataTable.ParseFromBytes(data.bytes);
                }

                ExcelQuery query = new ExcelQuery(filePath, sheetName);
                if (query != null && query.IsValid())
                {
                    dataTable.RemoveAllDataRows();
                    foreach (var da in query.Deserialize<ExcelExampleTempData>().ToArray())
                    {
                        dataTable.AddDataRow(da);
                    }
                    using (var fileStream = new FileStream(assetFilePath, FileMode.Create, FileAccess.Write))
                    {
                        using (var writer = new BinaryWriter(fileStream))
                        {
                            writer.Write(dataTable.ToBytes());
                            writer.Close();
                        }
                        fileStream.Close();
                    }
                }
            }
        }
    }
}
